import * as actions from '../action';

// 对页面prop 数据进行管理
const initialState = {
  dslFilterCondition: [
    { reservedKey: 'repo:', meaning: '代码库名称或路径' },
    { reservedKey: 'mine:', meaning: '是否是库成员' },
    { reservedKey: 'file:', meaning: '文件路径' },
    { reservedKey: 'ext:', meaning: '文件扩展名' },
    { reservedKey: 'lang:', meaning: '编程语言' },
    { reservedKey: 'author:', meaning: '作者' },
    { reservedKey: 'reviewer:', meaning: '合并请求评审人' },
    { reservedKey: 'mrstate:', meaning: '合并请求状态' },
    { reservedKey: 'visibility:', meaning: '可见性' },
  ],
  searchFeedback: { isShow: false, planId: '' },
  searchConfettiShow: false,
  dslErrorMessage: null,
  grammarCountList: [],
  headerInputStatus: false,
  headerModeStatus: 'ordinary',
  headerOneTips: false,
  headerSelectValue: 'all',
  headerInputValue: '',
  leftData: null,
  leftDataNum: 0,
  leftDataPage: { page: 1, page_size: 10 },
  leftLoading: false,
  leftMatchSelectValue: 'default',
  rowSpanCol: { left: '20', right: '4', middle: '0', middleState: false },
  middleData: {},
  middleLoading: false,
  leftDataSelectedValue: '',
  searchType: 'code',
  searchFilterValue: null,
  searchLanguageValue: null,
  searchRightMrValue: { establish: '', review: '', state: '' },
  searchMrData: [],
  searchCodeStorehouseData: [],
  searchCodeHouseType: {},
  searchVodeRepoSelectValue: { creatorId: '', visibility: '' },
  editorFocusObj: null,
};

export default function index(state = initialState, action) {
  switch (action.type) {
    case actions.SEARCH_CHANGE_FEEDBACK:
      return { ...state, searchFeedback: action.data };
    case actions.SEARCH_CONFETTI_CHANGE:
      return { ...state, searchConfettiShow: action.data };
    case actions.SEARCH_EDITOR_FOCUS_OBJ: // 拿到ediot可以聚焦的dom对象，给right_filterItem点击使用
      return { ...state, editorFocusObj: action.data };
    case actions.SEARCH_DSL_ERROR_MESSAGE_CHANGE:
      return { ...state, dslErrorMessage: action.data };
    case actions.SEARCH_RIGHT_GRAMMAR_COUNT_LIST:
      return { ...state, grammarCountList: action.data };
    case actions.SEARCH_HEADER_INPUT_STATUS_CHANGE:
      return { ...state, headerInputStatus: action.data };
    case actions.SEARCH_HEADER_MODE_STATUS:
      return { ...state, headerModeStatus: action.data };
    case actions.HEADER_SELECT_ON_CHANGE:
      return { ...state, headerSelectValue: action.data };
    case actions.SEARCH_HEADER_INPUT_CHANGE:
      return { ...state, headerInputValue: action.data };
    case actions.SEARCH_LEFT_CON_DATA:
      return { ...state, leftData: action.data.list || [], leftDataNum: action.data.amount };
    case actions.SEARCH_LEFT_CON_LOADING:
      return { ...state, leftLoading: action.data };
    case actions.SEARCH_LEFT_DATA_PAGIATION:
      return { ...state, leftDataPage: action.data };
    case actions.SEARCH_LEFT_SELECT_VALUE:
      return { ...state, leftMatchSelectValue: action.data };
    case actions.SEARCH_ROW_COL_SPAN:
      return { ...state, rowSpanCol: action.data, leftDataSelectedValue: action.data.previewDocId };
    case actions.SEARCH_GET_MIDDLE_DATA:
      return { ...state, middleData: action.data };
    case actions.SEARCH_MIDDLE_LOADING:
      return { ...state, middleLoading: action.data };
    case actions.SEARCH_SET_FILTER_VALUE:
      return { ...state, searchFilterValue: action.data };
    case actions.SEARCH_SET_SEARCH_TYPE:
      return { ...state, searchType: action.data };
    case actions.SEARCH_SET_SEARCH_LANGUAGE:
      return { ...state, searchLanguageValue: action.data };
    case actions.SEARCH_MR_STATE:
      return { ...state, searchRightMrValue: action.data };
    case actions.SEARCH_MR_SELECT_DATA:
      return { ...state, searchMrData: action.data };
    case actions.SEARCH_CODE_STORE_HOUSE_DATA:
      return { ...state, searchCodeStorehouseData: action.data };
    case actions.SEARCH_CODE_STORE_HOUSE_TYPE_VALUE:
      return { ...state, searchCodeHouseType: action.data };
    case actions.SEARCH_CODE_REPO_SELECT_VALUE:
      return { ...state, searchVodeRepoSelectValue: action.data };
    case actions.SEARCH_CODE_LEFT_LIST_DATA:
      return { ...state, leftData: action.data };
    case actions.HEAD_INPUT_STRING_ONE_TIPS:
      return { ...state, headerOneTips: action.data };
    default:
      return state;
  }
}
